home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-01-31 | 2.3 KB | 75 lines | [TEXT/ToyS] |
- -- run the script
- main()
-
-
- -- ----------------------------------------------------------------------
- -- Sample script for importing a text file straght into the caption
- -- of a field of a media object. This script goes thru' all items in a catalog
- -- opens associated text files (see function 'TextFileFromPath') and reads their
- -- text into the caption field.
- -- ----------------------------------------------------------------------
-
- on main()
- -- get the total number of items in the catalog
- tell application "iView Multimedia"
- set numObjects to the count objects of window 1
- end tell
-
- -- for each item in the catalog
- repeat with i from 1 to numObjects
-
- -- get the path of the item
- tell application "iView Multimedia"
- set thePath to the path of object i of window 1 as text
- end tell
-
- -- form associated filename
- set theTextFile to TextFileFromPath(thePath)
- set theData to ""
-
- -- read text file (if it exists)
- tell application "Finder"
- if (exists file (theTextFile)) then
- set theData to read file theTextFile as text
- get theData
- end if
- end tell
-
- -- if we have some data, paste it in the caption field
- if theData is not "" then
- tell application "iView Multimedia"
- set the annotations of object i of window 1 to {caption:theData}
- end tell
- end if
-
- end repeat
-
- -- bring iView to the front
- activate application "iView Multimedia"
- end main
-
-
- -- ----------------------------------------------------------------------
- -- In this script it is assumed that a text file is located at the same folder
- -- as the associated image and its name is:
- -- <image> name.i.jpg <text> name.txt.
- -- ----------------------------------------------------------------------
-
- on TextFileFromPath(thePath)
- set oldDelimiter to AppleScript's text item delimiters
-
- set AppleScript's text item delimiters to {":"}
- set countPathItems to (the number of text items in thePath) - 1
- set newPath to ""
- repeat with i from 1 to countPathItems
- set newPath to newPath & text item i of thePath & ":"
- end repeat
-
- set theName to the last text item of thePath
- set AppleScript's text item delimiters to {"."}
- set newPath to newPath & text item 1 of theName & ".txt"
-
- set AppleScript's text item delimiters to oldDelimiter
-
- return newPath
- end TextFileFromPath